package com.buba.controller;

import com.buba.pojo.Department;
import com.buba.pojo.Message;
import com.buba.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin(allowCredentials = "true",originPatterns = "*")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    @RequestMapping("/selectAll")
    public List<Department> seAll(){
        return departmentService.selAlls();
    }
    @DeleteMapping("/user")
    public Message del(@RequestParam("departId") String departId){
        int count = departmentService.dell(departId);
        if (count==0)
            return new Message(0,"删除失败");
        return new Message(1,"删除成功");
    }

    @PutMapping("/user")
    public Message upd(@RequestParam Map<String,Object> map){
        int count = departmentService.upd(map);
        if (count==0)
            return new Message(0,"修改失败");
        return new Message(1,"修改成功");
    }

    @PostMapping("/user")
    public Message ins(@RequestParam Map<String ,Object> map){
        int count = departmentService.ins(map);
        if (count==0)
            return new Message(0,"添加失败");
        return new Message(1,"添加成功");
    }


}
